package com.mall.service.commodity.controller;

import cn.hutool.core.convert.Convert;
import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.PmsProductAttribute;
import com.mall.service.commodity.service.ProductAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Ref;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ProductAttributeController
 * @Description 属性列表或参数列表
 * @Author dcq
 * @Date 2023/3/12 11:00
 * @Version 1.0
 */
@RestController
@RequestMapping("/productAttribute")
public class ProductAttributeController {
    @Autowired
    private ProductAttributeService productAttributeService;
    //属性参数  分页查询
    @GetMapping("/list/{cid}")
    public CommonResult<CommonPage> list(@PathVariable Integer cid, @RequestParam(defaultValue="1")Integer pageNum,
                                         @RequestParam(defaultValue = "10")Integer pageSize, Integer type){
          CommonPage commonPage=productAttributeService.listCid(cid,pageNum,pageSize,type);
          return CommonResult.success(commonPage);
    }
    //添加商品属性信息
    @PostMapping("/create")
    public  CommonResult create(@RequestBody PmsProductAttribute pmsProductAttribute){
        productAttributeService.creatSei(pmsProductAttribute);
        return  CommonResult.success(null,"添加成功");
    }

    // 单个商品属性
    @GetMapping("/{id}")
    public CommonResult<PmsProductAttribute>getById(@PathVariable Integer id){
        PmsProductAttribute pmsProductAttribute=productAttributeService.getByIdSei(id);
        return CommonResult.success(pmsProductAttribute);
    }
    //修改商品属性信息
    @PostMapping("/update/{id}")
    public CommonResult update (@PathVariable Integer id,@RequestBody PmsProductAttribute pmsProductAttribute ){
        pmsProductAttribute.setId(Convert.toLong(id));
        productAttributeService.updateSei(pmsProductAttribute);
        return CommonResult.success(null,"修改成功");
    }
    //批量删除属性 参数
    @PostMapping("/delete")
    public CommonResult delete(Integer[]ids ){
        productAttributeService.deleteSei(ids);
        return CommonResult.success(null,"删除成功");
    }
    //根据商品分类的id获取商品属性及属性分类
    @GetMapping("/attrInfo/{productCategoryId}")
    public CommonResult<List>attrInfo(@PathVariable Integer productCategoryId){
        List map=productAttributeService.atttrInfo(productCategoryId);
        return  CommonResult.success(map);
    }
}